function love.load()
    -- includes
    require("Button")
    require("Bullet")
    require("Menu")
    require("Plane")
    -- Initialize Others
    love.window.setTitle("Plane")
    love.graphics.setBackgroundColor(love.math.colorFromBytes(254, 254, 254))
    Font = love.graphics.newFont(20)
    -- Initialize Plane
    MyPlane = Plane:new(nil)
    -- Initialize Buttons
    Button_fire = Button:new(nil, 30, 80, "fire", 50, 530)
    Button_dash = Button:new(nil, 30, 80, "dash", 170, 530)
    Button_blink = Button:new(nil, 30, 80, "blink", 290, 530)
    Button_change = Button:new(nil, 30, 80, "change", 410, 530)
    Button_menu = Button:new(nil, 80, 80, "menu", 710, 50)
    listOfBullets = {}
    -- Initialize menu
    First_menu = Menu:new(nil, 100, 100)
    Button_back = Button:new(nil, 30, 80, 'back', 360, 260)
    Button_exit = Button:new(nil, 30, 80, 'exit', 360, 310)
    First_menu:addButton(Button_exit)
    First_menu:addButton(Button_back)
end
function love.draw()
    local mouse = {}
    mouse.x, mouse.y = love.mouse.getPosition()
    -- Plane
    MyPlane:draw()
    -- map
    love.graphics.setColor(love.math.colorFromBytes(0, 0, 0))
    love.graphics.setLineWidth(5)
    love.graphics.line(700, 0, 700, 500, 0, 500)
    Button_fire:draw()
    Button_dash:draw()
    Button_blink:draw()
    Button_change:draw()
    Button_menu:draw()
    -- Bullets
    for i, v in ipairs(listOfBullets) do
        v:draw()
    end
    if Button_menu.isDown then
        -- menu
        First_menu:draw()
    else
        -- sight
        MyPlane:sightDraw(mouse.x, mouse.y)
    end
end
function love.update(dt)
    local mouse = {}
    mouse.x, mouse.y = love.mouse.getPosition()
    if Button_menu.isDown then
        -- Button_exit
        Button_exit:mouseHover(mouse)
        if Button_exit.isDown then
            love.event.quit()
        end
        -- Button_back
        Button_back:mouseHover(mouse)
        if Button_back.isDown then
            Button_back.isDown = false
            Button_menu.isDown = false
        end
    else
        -- Plane move
        MyPlane:move(dt, mouse)
        -- Map_limit
        MyPlane:mapLimit()
        -- Button-fire
        Button_fire:mouseHover(mouse)
        -- Button_dash
        Button_dash:mouseHover(mouse)
        -- Button_blink
        Button_blink:mouseHover(mouse)
        -- Button_change
        Button_change:mouseHover(mouse)
        -- Button_menu
        Button_menu:mouseHover(mouse)
        -- Bullets
        for i, v in ipairs(listOfBullets) do
            v:update(dt)
            if v.x > 700 or v.x < 0 or v.y > 500 or v.y < 0 then
                table.remove(listOfBullets, i)
            end
        end
        -- dash
        if MyPlane.dash_on and dash_time + 1 <= love.timer.getTime() then
            MyPlane.speed = MyPlane.speed / MyPlane.dashSpeedRate
            MyPlane.dash_on = false
        end
        -- changeColor
        if Button_change.isDown then
            Button_change.isDown = false
            MyPlane:changeColor()
        end
    end
end
function love.mousepressed(x, y, button)
    if Button_menu.isDown then
        -- pass
    else
        -- Button_fire
        if Button_fire.isDown and button == 1 then
            table.insert(listOfBullets, Bullet:new(nil, MyPlane.x, MyPlane.y, 5, x, y, 1000))
        end
        -- Button_dash
        if Button_dash.isDown and button == 2 and MyPlane.dash_on == false then
            MyPlane.speed = MyPlane.speed * MyPlane.dashSpeedRate
            dash_time = love.timer.getTime()
            MyPlane.dash_on = true
        end
        -- Button_blink
        if Button_blink.isDown and button == 2 then
            MyPlane.x = MyPlane.x + math.cos(MyPlane.rotate) * MyPlane.blinkLength
            MyPlane.y = MyPlane.y + math.sin(MyPlane.rotate) * MyPlane.blinkLength
            MyPlane:mapLimit()
        end
    end
end
function love.mousereleased(x, y, button)
    if Button_menu.isDown then
        -- menu
        First_menu:downButtons(x, y, button)
    else
        -- Button_fire
        Button_fire:Down(x, y, button)
        -- Button_dash
        if Button_dash:Down(x, y, button) then
            Button_blink.isDown = false
        end
        -- Button_blink
        if Button_blink:Down(x, y, button) then
            Button_dash.isDown = false
        end
        -- Button_change
        Button_change:Down(x, y, button)
        -- Button_menu
        Button_menu:Down(x, y, button)
    end
end
